//
//  ExtractSubviewDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/26.
//

import SwiftUI

struct ExtractSubviewDemo: View {
    var body: some View {
        ZStack {
            Color.custom.ignoresSafeArea(.all)
            
            contentLayer
            
            
        }
        
    }
    
    var contentLayer: some View {
        //            myItem
        HStack {
            MyItem(title: "Apples", count: 1, color: .red)
            MyItem(title: "Oranges", count: 10, color: .orange)
            MyItem(title: "Bananas", count: 20, color: .yellow)

        }
    }
    
//    var myItem: some View {
//        VStack {
//            Text("1")
//            Text("Apples")
//        }
//        .padding()
//        .background(.red)
//        .cornerRadius(10)
//    }
}

#Preview {
    ExtractSubviewDemo()
}

struct MyItem: View {
    
    let title: String
    let count: Int
    let color: Color
    
    var body: some View {
        VStack {
            Text("\(count)")
            Text(title)
        }
        .padding()
        .background(color)
        .cornerRadius(10)
    }
}
